package com.gxuwz.attendance.action;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.gxuwz.attendance.util.VCodeUtil;
import com.opensymphony.xwork2.ActionSupport;



/**
 * 验证码处理
 * @author 蔡奇峰
 *
 */
public class VCodeAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	/**
	 * 生成验证码
	 */
	public void getVCode() {
		HttpServletRequest request = ServletActionContext.getRequest();
		
		HttpServletResponse response = ServletActionContext.getResponse();
		
		
		VCodeUtil util = new VCodeUtil();
		String vCode = util.generatorVCode();
		request.getSession().setAttribute("vCode", vCode);
		BufferedImage vCodeImage = util.generatorRotateVCodeImage(vCode, true);
		try {
			ImageIO.write(vCodeImage, "gif", response.getOutputStream());
		}catch(IOException e) {
			e.printStackTrace();
		}
		
	}
}
